#include <gtk/gtk.h>
#include <math.h>

static gboolean on_expose_event(GtkWidget *self,GdkEventExpose *event,gpointer data){
	//cairo_t *cr = gdk_cairo_create(self->window);
	printf("%s enter!\n",__func__);
	cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(self));
	cairo_arc(cr,200,200,100,0,2*M_PI);
	cairo_stroke(cr);

	cairo_set_line_width(cr,5);
	cairo_set_source_rgb(cr,1,0,0);
	cairo_move_to(cr,100,200);
	cairo_line_to(cr,300,200);
	cairo_stroke(cr);
	cairo_destroy(cr);

	return FALSE;
}

int main(int argc,char **argv){
	GtkWidget *w;
	gtk_init(&argc,&argv);
	w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	//g_signal_connect(G_OBJECT(w),"expose-event",G_CALLBACK(on_expose_event),NULL);
	g_signal_connect(G_OBJECT(w),"draw",G_CALLBACK(on_expose_event),NULL);
	g_signal_connect(G_OBJECT(w),"destroy",G_CALLBACK(gtk_main_quit),NULL);
	gtk_window_set_title(GTK_WINDOW(w),"cairo , 你好");
	gtk_window_set_position(GTK_WINDOW(w),GTK_WIN_POS_CENTER);
	gtk_window_set_default_size(GTK_WINDOW(w),400,400);

	gtk_widget_set_app_paintable(w,TRUE);
	gtk_widget_show_all(w);
	gtk_main();
	return 0;
}